<?php
/**
 * @Copyright Copyright (C) 2010-2012
 * @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
 + Created by:          Webit Solution
 * Company:		Webit Solution
 + Contact:		www.webits.asia, developer@webits.asia
 * Created on:	Mar 21, 2012
 ^
 + Project: 		WRecruit
 * File Name:	views/jobseeker/tmpl/job_apply.php
 ^ 
 * Description: template view to apply for a job
 ^ 
 * History:		NONE
 ^ 
 */
 
defined('_JEXEC') or die('Restricted access');
global $mainframe;
$user	=& JFactory::getUser();

$document =& JFactory::getDocument();
$document->addStyleSheet('components/com_wrecruit/css/'.$this->config['theme']);

$isShowButton = 1;
$newcvformlink = JRoute::_('index.php?option=com_wrecruit&view=candidates&layout=mycv&addtrigger=true');

if ($this->config['cur_location'] == 1) {
    if ($this->aj == '1'){ $vm=2; }
    else if ($this->aj == '2'){ $vm=3; }
    else if ($this->aj == '3'){ $vm=5; }
    else if ($this->aj == '4'){ $vm=5; }
}

if (!empty($this->userrole->rolefor) && $this->userrole->rolefor == 2) { // job seeker

//if ($this->totalresume > 0){ // Resume not empty

?>

<div class="content-left">
  <div class="box-list-job">
    <div class="job-seeker-panel"><?php include('components/com_wrecruit/views/candidates/tmpl/menuLeft.php');?></div>
    <div class="apply-job">
      <div class="head-title">
        <h2><?php echo JText::_('Apply For Job'); ?></h2>
      </div>
      <div class="job-view-content">
      	<p>To apply to this job vacancy, complete the information below by choosing your CV and giving your cover letter through our editor. We will process your application form and you will be notified about your application.</p>
        <form action="index.php" method="post" name="adminForm" id="adminForm">
          <?php if(count($this->jobs)): ?>
          <?php foreach($this->jobs as $job) { ?>
          <div class="view-apply-job">
            <h3 class="job-title"><?php echo $job->title ?></h3>
            <div id="job-describtion"><p><strong>Job Description</strong></p><?php echo $job->description; ?></div>
            <div class="form-row user-cv">
              <label for="cvid" class="label-field"><?php echo JText::_('Choose your CV'); ?>:</label>
              <?php //echo $this->myresumes; ?>
              <?php echo JHTML::_('select.genericList', $this->myresumes, 'cvid-'.$job->id, 'class="inputbox dropdown-box required" '. '', 'value', 'text', ''); ?> </div>
            <div class="user-cover-letter">
              <label><?php echo JText::_('Cover Letter:'); ?></label>
              <?php
                                $editor =& JFactory::getEditor();
                                //if(isset($this->resume))
                                    echo $editor->display('cover_letter-'.$job->id, '', '525', '140', '60', '20', false);
                                //else
                                //    echo $editor->display('resume', '', '550', '400', '60', '20', false);
                            ?>
            </div>
            <input type="hidden" name="jobids[]" value="<?php echo $job->id; ?>" />
          </div>
          <?php } ?>
          <?php endif; ?>
          <?php if ($isShowButton == 1) { ?>
          <input type="submit" class=" button gradient-button-yellow" name="submit_app" onclick="document.adminForm.submit();"  value="<?php echo JText::_('JS_APPLYNOW'); ?>" />
          </td>
          <?php 
                        }else if ($isShowButton == 2) { 
                            echo "<font color='red'><strong>" . JText::_('JS_JOBSTATUS') . " : " . $jobstatus[$this->job->jobstatus-1] . "</strong></font>"; 
                        }else if ($isShowButton == 3) { 
                            echo "<font color='red'><strong>" . JText::_('JS_EMP_APP_WAIT_APPROVAL')  . "</strong></font>"; 
                        }else if ($isShowButton == 4) { 
                            echo "<font color='red'><strong>" . JText::_('JS_EMP_APP_REJECT')  . "</strong></font>"; 
                        }
                    ?>
          <input type="hidden" name="view" value="application" />
          <input type="hidden" name="layout" value="static" />
          <input type="hidden" name="uid" value="<?php echo $this->uid; ?>" />
          <input type="hidden" name="option" value="<?php echo $this->option; ?>" />
          <input type="hidden" name="task" value="jobapply" />
          <input type="hidden" name="uid" value="<?php echo $this->uid; ?>" />
          <input type="hidden" name="apply_date" value="<?php echo date('Y-m-d H:i:s'); ?>" />
          <input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
        </form>
      </div>
    </div>
  </div>
</div>
<?php
/*}else{ // Employment application is empty
	echo '<p align="center">'.JText::_('EA_EMP_APP_EMPTY');

//echo '<br><br>'.$this->emplinks['empapp'].'</p>';
}*/
}elseif (!empty($this->userrole->rolefor) && $this->userrole->rolefor != 1) {
    if($this->config['visitor_show_login_message'] == 1){
	    $version = new JVersion;
	    $joomla = $version->getShortVersion();
		$jversion = substr($joomla,0,3);
        $redirectUrl = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=successfullogin';
        $redirectUrl = '&amp;return='.base64_encode($redirectUrl);
        $finalUrl = 'index.php?option=com_user&view=login'. $redirectUrl;
        if($jversion == '1.5') $finalUrl = 'index.php?option=com_user&view=login'. $redirectUrl;
        else $finalUrl = 'index.php?option=com_users&view=login'. $redirectUrl;
        $finalUrl = JRoute::_($finalUrl);
        $formresumelink = JRoute::_('index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=formresume');
        echo 'Please login to record your resume for future use';
        echo "<br><a href='".$finalUrl."'><strong>Login</strong></a> OR <strong><a href='".$formresumelink."'>Job Apply as a visitor</a></strong>";
    }


} else{ // not allowed job posting
	//Update by Vireak on 09/08/2012
	//Add frame to this warning and some styling
	//---------------------
	echo '<div class="box-list"><div class="head-title"><h2>Oop!</h2></div>';
	echo '<span class="wr_info"><p>'.JText::_('JS_YOU_ARE_NOT_ALLOWED_TO_VIEW').'</p>';
	echo '<p>This page is reserved for the authorized candidates only. </p></span>';
	echo '</div>';
	//---------------------
}

?>
<div width="100%">
  <?php 
if($this->config['fr_cr_txsh']) {
	echo 
	'<table width="100%" style="table-layout:fixed;">
		<tr><td height="15"></td></tr>
		<tr><td style="vertical-align:top;" align="center">'.$this->config['fr_cr_txa'].$this->config['fr_cr_txb'].'</td></tr>
	</table>';
}	
?>
</div>
